import { useRequest } from 'ahooks'
import request from '../../../utils/request'
export function useFormData(setShowLogin) {
    const addCommentApi = data => {
        return request({
            url: '/comment/addComment',
            data,
            method: 'POST'
        })
    }
    const { loading, run } = useRequest(addCommentApi, {
        manual: true,
        onSuccess: res => {
            window.$message.success('操作成功')
        },
        onError: error => {
            if(error.status === 401) {
                setShowLogin(true)
            }
        }
    })
    const submit = formData =>{
        run(formData)
    }
    return {
        loading,
        submit
    }
}
